let expess = require('express');
let router = expess.Router()

let mgdb = require('../../utils/mgdb')

//所有列表接口
router.get('/:listname', (req, res, next) => {

    // console.log('news/xx',req.query._page,req.query._limit,req.body.q,req.headers._sort);

    let collectionName = req.params.listname;
    let { _page, _limit, _sort, q } = req.query;

    mgdb.findList({ collectionName, _page, _sort, _limit, q }).then(
        result => res.send(result)
    ).catch(
        err => res.send(err)
    )

})

//所有详情结构
router.get('/:listname/:_id', (req, res, next) => {
    // console.log('news/xx/id',req.query._page,req.query._limit,req.body.q,req.headers._sort)
    let collectionName = req.params.listname;
    let _id = req.params._id;

    mgdb.findDetail({ collectionName, _id }).then(
        result => res.send(result)
    ).catch(
        err => res.send(err)
    )
})


module.exports = router;